package com.aranandroid.customview.dialog

import android.content.Context
import android.view.View
import android.widget.TextView


class DialogTipsUtils private constructor() {
    /**
     * 两个按钮，两个回调
     *
     * @param context
     * @param string
     * @param listenerno
     * @param listeneryes
     */
    fun showTipsDialog(
        context: Context?,
        string: String?,
        confirmListenter: ((view: View, dialog: CustomDialog) -> Unit)?,
        cancleListenter: ((view: View, dialog: CustomDialog) -> Unit)?
    ) {
        val builder = CustomDialog.Builder(
            context!!
        )
        val customDialog = builder.dialogLayoutId(R.layout.dialog_prompt)
            .tempStyles { title, cancel, confirm, config, contentLayout, bottomLayout, middle, lineBottom ->
                title.visibility = View.GONE
            }
            .confirmListenter { v, dialog ->
                confirmListenter?.let { it(v, dialog) }
            }
            .cancelListenter { v, dialog ->
                cancleListenter?.let { it(v, dialog) }
            }
            .build()
        (customDialog.childView!!.findViewById<View>(R.id.tv_remark) as TextView).apply{
            setTextSize(16f)
            setText(string)
        }
        customDialog.show()
    }

    /**
     * 一个按钮，一个回调
     *
     * @param context
     * @param string
     * @param listeneryes
     */
    fun showTipsDialog(
        context: Context?,
        string: String?,
        confirmListenter: ((view: View, dialog: CustomDialog) -> Unit)?
    ) {
        val builder = CustomDialog.Builder(
            context!!
        )
        val customDialog =
            builder.dialogLayoutId(R.layout.dialog_prompt).confirmnoly(true)
                .tempStyles { title, cancel, confirm, config, contentLayout, bottomLayout, middle, lineBottom ->
                    title.visibility = View.GONE
                }
                .confirmListenter { v, dialog ->
                    confirmListenter?.let { it(v, dialog) }
                }.build()
        (customDialog.childView!!.findViewById<View>(R.id.tv_remark) as TextView).apply{
            setTextSize(16f)
            setText(string)
        }
        customDialog.show()
    }


    companion object {
        private var dialogUtils: DialogTipsUtils? = null

        @get:Synchronized
        val instance: DialogTipsUtils?
            get() {
                if (dialogUtils == null) dialogUtils = DialogTipsUtils()
                return dialogUtils
            }
    }
}